package com.lan.controller.formdata;

import org.apache.commons.lang3.RandomUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  表格数据
 * </p>
 *
 *
 * @author shadow
 * @since 2022-10-16
 */
@Controller
@RequestMapping("formData")
public class FormDataController {

    /**
     * 饼状图
     *
     * */
    @RequestMapping("proportion")
    public String proportion(final ModelMap model) {
        Map<String, Integer> map = new HashMap<>();
        map.put("sleep", 800);
        map.put("work", 700);
        map.put("study", 100);
        map.put("game", 100);
        map.put("walk", 10);
        model.addAttribute("map", map);
        return "formData/proportion";
    }

    /**
     * 曲线图
     *
     * */
    @RequestMapping("columnChart")
    public String columnChart(final ModelMap model) {
        List<String> xList = new ArrayList<>();
        List<Integer> dataList = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            xList.add(i + "");
            dataList.add(RandomUtils.nextInt(1, 10));
        }
        model.addAttribute("xList", xList);
        model.addAttribute("dataList", dataList);
        return "formData/columnChart";
    }
}
